﻿using AutoMapper;
using B.S.Database.Domain.Entity;
using B.S.Database.ErrorCode;
using B.S.Database.Interface.Interface;
using B.S.Database.Read.Api.Application.Commands.Breeding;
using MediatR;

namespace B.S.Database.Read.Api.Application.CommandHandler.Breeding
{
    public class CompanyShowCommandHandller : IRequestHandler<CompanyShowCommands, Apiresult<List<Company_Information>>>
    {
        private readonly IBaseResotity<Company_Information> companyRepo;

        public CompanyShowCommandHandller(IBaseResotity<Company_Information> CompanyRepo)
        {
            companyRepo = CompanyRepo;
        }
        public Task<Apiresult<List<Company_Information>>> Handle(CompanyShowCommands request, CancellationToken cancellationToken)
        {
            Apiresult<List<Company_Information>> res = new Apiresult<List<Company_Information>>();
            res.Code = ApiEnums.成功;
            res.Message = ApiEnums.成功.ToString();
            var list = companyRepo.GetAll().Where(c => c.TraceabilityId == request.TraceabilityId);
            res.Data = list.ToList();
            return Task.FromResult(res);
        }
    }
}
